// import request from '@/utils/request'

// export default {
//     setDa42Questions(engine,ata22Type){
//         return request({
//             url: `/settingQuestions/Da42/${engine}/${ata22Type}`,
//             method: 'get'
//         })
//     }
// }

import axios from "axios";
import store from "@/store";
import { getToken } from "@/utils/auth";
import host from "@/utils/host";

let token = "";

if (store.getters.token) {
  // let each request carry token
  // ['X-Token'] is a custom headers key
  // please modify it according to the actual situation
  token = getToken();
}

export default {
  setDa42Questions(engine, ata22Type, name) {
    const url = `http://${host}:8080/elearning/settingQuestions/Da42/${engine}/${ata22Type}`;
    axios
      .get(url, {
        headers: {
          Authorization: token,
        },
        responseType: "blob", // 指定响应类型为二进制数据
      })
      .then((response) => {
        const blob = new Blob([response.data], {
          type: "text/plain",
        });
        const url = window.URL.createObjectURL(blob);
        const link = document.createElement("a");
        link.href = url;
        link.setAttribute("download", `${name}的DA42考卷.docx`);
        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link);
      })
      .catch((error) => {
        // 处理错误
      });
  },

  setDa42Sup(name) {
    const url = `http://${host}:8080/elearning/settingQuestions/Da42/sup`;
    axios
      .get(url, {
        headers: {
          Authorization: token,
        },
        responseType: "blob", // 指定响应类型为二进制数据
      })
      .then((response) => {
        const blob = new Blob([response.data], {
          type: "text/plain",
        });
        const url = window.URL.createObjectURL(blob);
        const link = document.createElement("a");
        link.href = url;
        link.setAttribute("download", `${name}的DA42考卷.docx`);
        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link);
      })
      .catch((error) => {
        // 处理错误
      });
  },
};
